//编辑项目经验
import React, { Component } from 'react'
import {
    View,
    Text,
    TextInput,
    TouchableOpacity,
    ScrollView,
} from 'react-native';

import { getSize } from '../../../../util/sizeUtil'
import { eduedit_Style as styles } from '../../../../../styles';
import { posedit_Style as styles1 } from '../../../../../styles';
import Icon from 'react-native-vector-icons/Ionicons';
import Autoinput2 from '../../../../util/inputUtil2';
import Timeutil from '../../../../util/newtimeUtil';
import fmt from '../../../../util/fmtDateUtil';
import { fetchRequest } from '../../../../util/fetch';
import { myAlert } from '../../../../util/compatible';

var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;

export default class Proedit_body extends Component {
    constructor(props) {
        super(props);
        this.state = {
            xzProjectExp: {}
        };
    }

    //加载后渲染页面
    componentDidMount() {
        if (!this.state.xzProjectExp.proexpId && this.props.xzProjectExp.proexpId) {
            this.setState({ xzProjectExp: this.props.xzProjectExp })
        }
    }

    render() {
        return (
            <View>
                <View style={[styles1.rtopin, {
                    width: width * 1,
                    elevation: 5,
                    shadowColor: 'black',
                    shadowOpacity: 1,
                    shadowRadius: 5
                }]}>

                    <TouchableOpacity activeOpacity={1} style={styles1.rtopicon1} onPress={() => { this.props.navigation.goBack() }}>
                        <Icon
                            name={'ios-arrow-back'}
                            size={25}
                            color={'#ffffff'} />
                    </TouchableOpacity>
                    <Text style={styles1.rtoptext}>项目经验</Text>

                    <TouchableOpacity style={styles1.rtoptextout}
                        onPress={() => {
                            const xzProjectExp = {
                                proexpId: this.state.xzProjectExp.proexpId,
                                resumeId: this.props.resume.resumeId,
                                proexpName: this.state.xzProjectExp.jobexpCompanyName,
                                proexpBeginTime: fmt(this.state.xzProjectExp.proexpBeginTime, 'yyyy-MM-dd HH:mm:ss'),
                                proexpEndTime: fmt(this.state.xzProjectExp.proexpEndTime, 'yyyy-MM-dd HH:mm:ss'),
                                proexpPostion: this.state.xzProjectExp.proexpPostion,
                                proexpDescribe: this.state.xzProjectExp.proexpDescribe,
                                proexpDuty: this.state.xzProjectExp.proexpDuty,
                            }
                            if (xzProjectExp.proexpId) {
                                this.props.actions.UpdateEducationAction(xzProjectExp);
                                this.props.navigation.goBack();
                            } else {
                                this.props.actions.InsertProAction(xzProjectExp);
                                this.props.navigation.goBack();
                            }
                        }}
                    >
                        <Text style={styles1.rtoptext2}>保存</Text>
                    </TouchableOpacity>
                </View >

                <ScrollView style={styles.rout} ref="sv">

                    {/* 项目名称 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>项目名称</Text>
                        <TextInput
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            defaultValue={this.state.xzProjectExp.proexpName}
                            onChangeText={this.proexpName.bind(this)}

                        />
                    </View>

                    {/* 开始时间 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>开始时间</Text>
                        <Timeutil
                            function={this.proexpBeginTime.bind(this)}
                            time={this.state.xzProjectExp.proexpBeginTime}
                        />
                    </View>

                    {/* 结束时间 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>结束时间</Text>
                        <Timeutil
                            function={this.proexpEndTime.bind(this)}
                            time={this.state.xzProjectExp.proexpEndTime}
                        />
                    </View>

                    {/* 项目职务 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>项目职务</Text>
                        <TextInput
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            defaultValue={this.state.xzProjectExp.proexpPostion}
                            onChangeText={this.proexpPostion.bind(this)}
                        />
                    </View>

                    {/* 项目描述 */}
                    <View style={styles.rmall2} ref="v1">
                        <Text style={styles.rtxt2}>项目描述</Text>
                        <Autoinput2
                            style={[styles.inputname, { width: width * 0.7 }]}
                            function={this.proexpDescribe.bind(this)}
                            text={this.state.xzProjectExp.proexpDescribe}
                            onChange={this.gooo.bind(this)}
                            onFocus={this.gooo.bind(this)}
                        />
                    </View>

                    {/* 项目职责 */}
                    <View style={styles.rmall2} ref="v2">
                        <Text style={styles.rtxt2}>项目职责</Text>
                        <Autoinput2
                            style={[styles.inputname, { width: width * 0.7 }]}
                            function={this.proexpDuty.bind(this)}
                            text={this.state.xzProjectExp.proexpDuty}
                            onChange={this.gooo.bind(this)}
                            onFocus={this.gooo.bind(this)}
                        />
                    </View>

                    <View style={{ height: 100,alignItems:'flex-end' }}>
                        {this.state.xzProjectExp.proexpId ?
                            <TouchableOpacity style={styles.del_all} activeOpacity={1} onPress={() => { this._delProject(this.state.xzProjectExp.proexpId) }}>
                                <Text style={styles.del}>删除</Text>
                            </TouchableOpacity>
                            :
                            null
                        }
                    </View>

                </ScrollView >
            </View>
        )
    }

    _delProject(projectExpId) {
        fetchRequest('ProjectExp/deleteProjectExpMob.go', 'POST', { projectExpId: projectExpId }).then(ret => {
            if (ret.msg == 'ok') {
                this.props.actions.EditResumeAction();
                this.props.navigation.goBack();
            } else {
                myAlert('删除失败')
            }
        })
    }

    //项目名称
    proexpName(a) {
        const xzProjectExp = this.state.xzProjectExp;
        xzProjectExp.proexpName = a;
        this.setState({ xzProjectExp: xzProjectExp });
    }

    //开始时间
    proexpBeginTime(a) {
        const xzProjectExp = this.state.xzProjectExp;
        xzProjectExp.proexpBeginTime = a;
        this.setState({ xzProjectExp: xzProjectExp });
    }

    //结束时间
    proexpEndTime(a) {
        const xzProjectExp = this.state.xzProjectExp;
        xzProjectExp.proexpEndTime = a;
        this.setState({ xzProjectExp: xzProjectExp });
    }

    //项目职务
    proexpPostion(a) {
        const xzProjectExp = this.state.xzProjectExp;
        xzProjectExp.proexpPostion = a;
        this.setState({ xzProjectExp: xzProjectExp });
    }

    //项目描述
    proexpDescribe(a) {
        const xzProjectExp = this.state.xzProjectExp;
        xzProjectExp.proexpDescribe = a;
        this.setState({ xzProjectExp: xzProjectExp });
    }

    //项目职责
    proexpDuty(a) {
        const xzProjectExp = this.state.xzProjectExp;
        xzProjectExp.proexpDuty = a;
        this.setState({ xzProjectExp: xzProjectExp });
    }
    gooo() {
        getSize(this.refs.v1).then(res => {
            this.refs.sv.scrollTo({ x: 0, y: (res.height + res.pageY), animated: true })
        })
        getSize(this.refs.v2).then(res => {
            this.refs.sv.scrollTo({ x: 0, y: (res.height + res.pageY), animated: true })
        })
    }

}